<?php 
echo 'send';
$dbconn=pg_connect("host=localhost port=5432 dbname=sms user=postgres password=admin");
$result=pg_query($dbconn,"select * from out_get(3)");
$numrows=pg_numrows($result);var_dump($numrows);
if($numrows==0){
    pg_close($dbconn);
    exit;
}
include_once 'HTTP/Request2.php';
$r=new HTTP_Request2('http://onesms.mobifone.com.vn/login.action',HTTP_Request2::METHOD_POST);
$r->setConfig('connect_timeout',20);
$r->setConfig('timeout',30);
$r->setCookieJar(true);
$r->addPostParameter('username','sctvquangninh');
$r->addPostParameter('password','123456abc');
$r->addPostParameter('method:execute','');
$r->addPostParameter('hidden_identifier','');
$r->addPostParameter('hidden_oid_type','');
$response=$r->send();
if(200==$response->getStatus()){
    $cookies=$r->getCookieJar();
    $results=pg_fetch_all($result);
    foreach($results as $key=>$row){
        $r=new HTTP_Request2('http://onesms.mobifone.com.vn/schedule',HTTP_Request2::METHOD_POST);
        $r->setConfig('connect_timeout',20);
        $r->setConfig('timeout',30);
        $r->setCookieJar($cookies);
        $r->addPostParameter('action','sendSMS');
        $r->addPostParameter('id_org','1396');
        $r->addPostParameter('strCheck',$row['receiver']);
        $r->addPostParameter('sms',$row['msg']);
        $r->addPostParameter('sendType','0');
        $r->addPostParameter('brandName','SCTV QN');
        $r->addPostParameter('msisdn','84905000705');
        $r->addPostParameter('shortCode','');
        $r->addPostParameter('sendCheck','0');
        $r->addPostParameter('sendDate','');
        $r->addPostParameter('sendTime',null);
        $r->addPostParameter('description','');
        $r->addPostParameter('username','sctvquangninh');
        $response=$r->send();
        if(200==$response->getStatus() && $response->getBody()=='1'){
            pg_query_params($dbconn,"select out_update_sent($1,$2)",array($row['id'],'84905000705'));
        }else{
            break;
        }
    }
}
pg_close($dbconn);
?>